#include "cellmainwindow.h"
#include <QtWidgets>

void CellMainWindow::keyPressEvent(QKeyEvent *event)
{
    switch(event->key())
    {
        case Qt::Key_Shift:
            perspectiveWidget->setKeyValue(CELL_SHIFT);
            break;
        case Qt::Key_Backspace:
            if (perspectiveWidget->getSelectMode() != CELL_SELECT)
            {
                perspectiveWidget->deleteSelect();
            }
            else
            {
                perspectiveWidget->deleteSelectedObject();
            }
            break;
        case Qt::Key_Alt:
            perspectiveWidget->setTmpMode(CELL_CAMERAROTATE);
            break;
        case Qt::Key_Control:
            perspectiveWidget->setTmpMode(CELL_CAMERAMOVE);
            break;
        default:
            perspectiveWidget->setKeyValue(CELL_KEYRELEASE);
            break;
    }
    perspectiveWidget->updateGL();
}

void CellMainWindow::keyReleaseEvent(QKeyEvent *event)
{
    switch(event->key())
    {
        case Qt::Key_Alt:
            perspectiveWidget->resetTmpMode();
            break;
        case Qt::Key_Control:
            perspectiveWidget->resetTmpMode();
            break;
    }

    perspectiveWidget->setKeyValue(CELL_KEYRELEASE);
    perspectiveWidget->updateGL();
}


void CellMainWindow::mousePressEvent(QMouseEvent *event)
{
    int xx = event->pos().x();
    int yy = event->pos().y();
    //if you clicking inside the window
    if (xx >= CELL_OPENGLOFFSETX && yy >= CELL_OPENGLOFFSETY && xx < perspectiveWidget->width()+CELL_OPENGLOFFSETX && yy < perspectiveWidget->height()+CELL_OPENGLOFFSETY)
    {
        // construct a mouse event so you can pass it later
        QMouseEvent *pevent = new QMouseEvent(event->type() , QPointF(event->windowPos().x(), event->windowPos().y()),
                                              event->button(), event->buttons(), event->modifiers());
        // COMBINE BEGIN
        /*
        if (perspectiveWidget->getMode() == CELL_SELECT && perspectiveWidget->getSelectMode() == CELL_SELECT)
        {
            //construct the new command
            recCommand = new SelectObjectCommand(perspectiveWidget, perspectiveWidget->selectedObject());

            //pass the mouse event to the GLWidget window
            perspectiveWidget->myMousePressEvent(pevent);
            //if selected a new/different object, push that command to the undo stack
            ((SelectObjectCommand*)recCommand)->setRecSelectObject(perspectiveWidget->selectedObject());
            if (((SelectObjectCommand*)recCommand)->isSelectChanged())
            {
                undoStack->push(recCommand);
            }
        }
        */
        if (perspectiveWidget->getMode() == CELL_TRANSLATE && perspectiveWidget->getSelectMode() == CELL_SELECT)
        {
            //construct the new command
            recCommand = new SelectObjectCommand(perspectiveWidget, perspectiveWidget->selectedObject());

            //pass the mouse event to the GLWidget window
            perspectiveWidget->myMousePressEvent(pevent);
            //if selected a new/different object, push that command to the undo stack
            ((SelectObjectCommand*)recCommand)->setRecSelectObject(perspectiveWidget->selectedObject());
            if (((SelectObjectCommand*)recCommand)->isSelectChanged())
            {
                undoStack->push(recCommand);
            }



            if (perspectiveWidget->selectedObject()==0) {
                recCommand = new TranslateCommand(perspectiveWidget,
                                                  perspectiveWidget->getGlandular()->getTranslateX(),
                                                  perspectiveWidget->getGlandular()->getTranslateY(),
                                                  perspectiveWidget->getGlandular()->getTranslateZ(),
                                                  perspectiveWidget->getGlandular()->getTranslateX(),
                                                  perspectiveWidget->getGlandular()->getTranslateY(),
                                                  perspectiveWidget->getGlandular()->getTranslateZ(),
                                                  perspectiveWidget->selectedObject());
                perspectiveWidget->myMousePressEvent(pevent);
            } else if (perspectiveWidget->selectedObject()>1) {
                recCommand = new TranslateCommand(perspectiveWidget,
                                                  (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getTranslateX(),
                                                  (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getTranslateY(),
                                                  (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getTranslateZ(),
                                                  (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getTranslateX(),
                                                  (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getTranslateY(),
                                                  (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getTranslateZ(),
                                                  perspectiveWidget->selectedObject());
                perspectiveWidget->myMousePressEvent(pevent);
            }
        } // COMBINE END
        else if (perspectiveWidget->getMode()==CELL_TRANSLATE && (perspectiveWidget->getSelectMode()==CELL_EDITMESHPOINT||perspectiveWidget->getSelectMode()==CELL_EDITMESHFACE))
        {
            if (perspectiveWidget->selectedObject() == 0)
            {
                recCommand = new MeshChangedCommand(perspectiveWidget,
                                                    perspectiveWidget->getGlandular(),
                                                    perspectiveWidget->selectedObject());
                perspectiveWidget->myMousePressEvent(pevent);
            }
            else if (perspectiveWidget->selectedObject() > 1)
            {
                recCommand = new MeshChangedCommand(perspectiveWidget,
                                                    (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2)),
                                                    perspectiveWidget->selectedObject());
                perspectiveWidget->myMousePressEvent(pevent);
            }
        }
        else if (perspectiveWidget->getMode() == CELL_TRANSLATE && perspectiveWidget->getSelectMode() == CELL_SELECT)
        {
            if (perspectiveWidget->selectedObject()==0) {
                recCommand = new TranslateCommand(perspectiveWidget,
                                                  perspectiveWidget->getGlandular()->getTranslateX(),
                                                  perspectiveWidget->getGlandular()->getTranslateY(),
                                                  perspectiveWidget->getGlandular()->getTranslateZ(),
                                                  perspectiveWidget->getGlandular()->getTranslateX(),
                                                  perspectiveWidget->getGlandular()->getTranslateY(),
                                                  perspectiveWidget->getGlandular()->getTranslateZ(),
                                                  perspectiveWidget->selectedObject());
                perspectiveWidget->myMousePressEvent(pevent);
            } else if (perspectiveWidget->selectedObject()>1) {
                recCommand = new TranslateCommand(perspectiveWidget,
                                                  (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getTranslateX(),
                                                  (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getTranslateY(),
                                                  (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getTranslateZ(),
                                                  (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getTranslateX(),
                                                  (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getTranslateY(),
                                                  (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getTranslateZ(),
                                                  perspectiveWidget->selectedObject());
                perspectiveWidget->myMousePressEvent(pevent);
            }
        }
        else if (perspectiveWidget->getMode()==CELL_ROTATE && perspectiveWidget->getSelectMode()==CELL_SELECT)
        {
            if (perspectiveWidget->selectedObject()==0)
            {
                recCommand = new RotateCommand(perspectiveWidget,
                                               perspectiveWidget->getGlandular()->getRotateX(),
                                               perspectiveWidget->getGlandular()->getRotateY(),
                                               perspectiveWidget->getGlandular()->getRotateZ(),
                                               perspectiveWidget->getGlandular()->getRotateX(),
                                               perspectiveWidget->getGlandular()->getRotateY(),
                                               perspectiveWidget->getGlandular()->getRotateZ(),
                                               perspectiveWidget->selectedObject());
                perspectiveWidget->myMousePressEvent(pevent);
            }
            else if (perspectiveWidget->selectedObject()>1)
            {
                recCommand = new RotateCommand(perspectiveWidget,
                                               (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getRotateX(),
                                               (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getRotateY(),
                                               (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getRotateZ(),
                                               (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getRotateX(),
                                               (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getRotateY(),
                                               (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getRotateZ(),
                                               perspectiveWidget->selectedObject());
                perspectiveWidget->myMousePressEvent(pevent);
            }
        }
        else if (perspectiveWidget->getMode()==CELL_SCALE && perspectiveWidget->getSelectMode()==CELL_SELECT)
        {
            if (perspectiveWidget->selectedObject()==0)
            {
                recCommand = new ScaleCommand(perspectiveWidget,
                                              perspectiveWidget->getGlandular()->getScaleX(),
                                              perspectiveWidget->getGlandular()->getScaleY(),
                                              perspectiveWidget->getGlandular()->getScaleZ(),
                                              perspectiveWidget->getGlandular()->getScaleX(),
                                              perspectiveWidget->getGlandular()->getScaleY(),
                                              perspectiveWidget->getGlandular()->getScaleZ(),
                                              perspectiveWidget->selectedObject());
                perspectiveWidget->myMousePressEvent(pevent);
            }
            else if (perspectiveWidget->selectedObject()>1)
            {
                recCommand = new ScaleCommand(perspectiveWidget,
                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getScaleX(),
                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getScaleY(),
                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getScaleZ(),
                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getScaleX(),
                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getScaleY(),
                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getScaleZ(),
                                              perspectiveWidget->selectedObject());
                perspectiveWidget->myMousePressEvent(pevent);
            }
        }
        perspectiveWidget->myMousePressEvent(pevent);
        perspectiveWidget->updateGL();
    }
}

void CellMainWindow::mouseMoveEvent(QMouseEvent *event)
{
    int xx = event->pos().x();
    int yy = event->pos().y();
    if (xx>=CELL_OPENGLOFFSETX&&yy>=CELL_OPENGLOFFSETY&&xx<perspectiveWidget->width()+CELL_OPENGLOFFSETX&&yy<perspectiveWidget->height()+CELL_OPENGLOFFSETY) {
        QMouseEvent *pevent = new QMouseEvent(event->type() , QPointF(event->windowPos().x(), event->windowPos().y()),
                                              event->button(), event->buttons(), event->modifiers());
        perspectiveWidget->myMouseMoveEvent(pevent);
    }
}


void CellMainWindow::mouseReleaseEvent(QMouseEvent *event)
{
    int xx = event->pos().x();
    int yy = event->pos().y();
    if (xx>=CELL_OPENGLOFFSETX&&yy>=CELL_OPENGLOFFSETY&&xx<perspectiveWidget->width()+CELL_OPENGLOFFSETX&&yy<perspectiveWidget->height()+CELL_OPENGLOFFSETY) {
        QMouseEvent *pevent = new QMouseEvent(event->type() , QPointF(event->windowPos().x(), event->windowPos().y()),
                                              event->button(), event->buttons(), event->modifiers());
        if(recCommand != NULL) {
            if (perspectiveWidget->getMode()==CELL_TRANSLATE && (perspectiveWidget->getSelectMode()==CELL_EDITMESHPOINT||perspectiveWidget->getSelectMode()==CELL_EDITMESHFACE)) {
                undoStack->push(recCommand);
            }
            if (perspectiveWidget->getMode()==CELL_TRANSLATE && perspectiveWidget->getSelectMode()==CELL_SELECT) {
                if (perspectiveWidget->selectedObject()==0) {
                    ((TranslateCommand*)recCommand)->setNew(perspectiveWidget->getGlandular()->getTranslateX(),
                                                            perspectiveWidget->getGlandular()->getTranslateY(),
                                                            perspectiveWidget->getGlandular()->getTranslateZ());
                } else if (perspectiveWidget->selectedObject()>1) {
                    ((TranslateCommand*)recCommand)->setNew((perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getTranslateX(),
                                                            (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getTranslateY(),
                                                            (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getTranslateZ());
                }
                undoStack->push(recCommand);
            } else if (perspectiveWidget->getMode()==CELL_ROTATE && perspectiveWidget->getSelectMode()==CELL_SELECT) {
                if (perspectiveWidget->selectedObject()==0) {
                    ((RotateCommand*)recCommand)->setNew(perspectiveWidget->getGlandular()->getRotateX(),
                                                         perspectiveWidget->getGlandular()->getRotateY(),
                                                         perspectiveWidget->getGlandular()->getRotateZ());
                } else if (perspectiveWidget->selectedObject()>1) {
                    ((RotateCommand*)recCommand)->setNew((perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getRotateX(),
                                                         (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getRotateY(),
                                                         (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getRotateZ());
                }
                undoStack->push(recCommand);
            } else if (perspectiveWidget->getMode()==CELL_SCALE && perspectiveWidget->getSelectMode()==CELL_SELECT) {
                if (perspectiveWidget->selectedObject()==0) {
                    ((ScaleCommand*)recCommand)->setNew(perspectiveWidget->getGlandular()->getScaleX(),
                                                        perspectiveWidget->getGlandular()->getScaleY(),
                                                        perspectiveWidget->getGlandular()->getScaleZ());
                } else if (perspectiveWidget->selectedObject()>1) {
                    ((ScaleCommand*)recCommand)->setNew((perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getScaleX(),
                                                        (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getScaleY(),
                                                        (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getScaleZ());
                }
                undoStack->push(recCommand);
            }
        }
        perspectiveWidget->myMouseReleaseEvent(pevent);
        perspectiveWidget->updateGL();
    }
}

void CellMainWindow::paintToolGroupReleased(QAbstractButton *button)
{
    QList<QAbstractButton *> buttons = transformToolGroup->buttons();
    foreach (QAbstractButton *myButton, buttons) {
        if (myButton != button)
        button->setChecked(false);
    }
}

void CellMainWindow::paintToolGroupPressed(QAbstractButton *button)
{
    button->setChecked(true);
    QString text = button->objectName();
    if (text == tr("Sphere")) {
        //perspectiveWidget->addCylinder();
        QUndoCommand *addObjectCommand = new AddObjectCommand(perspectiveWidget, CELL_SPHERE);
        undoStack->push(addObjectCommand);
    } else if (text == tr("Closed Cylinder")) {
        //perspectiveWidget->addSphere();
        QUndoCommand *addObjectCommand = new AddObjectCommand(perspectiveWidget, CELL_CYLINDER);
        undoStack->push(addObjectCommand);
    } else if (text == tr("Cube")) {
        //perspectiveWidget->addCube();
        QUndoCommand *addObjectCommand = new AddObjectCommand(perspectiveWidget, CELL_CUBE);
        undoStack->push(addObjectCommand);
    } else if (text == tr("Open Cylinder")) {
        //perspectiveWidget->addOpenCylinder();
        QUndoCommand *addObjectCommand = new AddObjectCommand(perspectiveWidget, CELL_OPENCYLINDER);
        undoStack->push(addObjectCommand);
    } else if (text == tr("Plane")) {
        QUndoCommand *addObjectCommand = new AddObjectCommand(perspectiveWidget, CELL_PLANE);
        undoStack->push(addObjectCommand);
    } else if (text == tr("Line")) {
        QUndoCommand *addObjectCommand = new AddObjectCommand(perspectiveWidget, CELL_LINE);
        undoStack->push(addObjectCommand);
    }
}

void CellMainWindow::setSphereRadius(QString l)
{
    double t = l.toDouble();
    if (t>0.0) {
        QUndoCommand *sphereInputCommand = new SphereInputCommand(perspectiveWidget, perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getSphereRadius(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getSphereHeightSeg(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getSphereAxisSeg(),
                                                              t,
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getSphereHeightSeg(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getSphereAxisSeg());
        undoStack->push(sphereInputCommand);
    }
    perspectiveWidget->updateGL();
}

void CellMainWindow::setSphereHeightSeg(QString l)
{
    int t = l.toInt();
    if (t>=2) {
        QUndoCommand *sphereInputCommand = new SphereInputCommand(perspectiveWidget, perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getSphereRadius(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getSphereHeightSeg(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getSphereAxisSeg(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getSphereRadius(),
                                                              t,
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getSphereAxisSeg());
        undoStack->push(sphereInputCommand);
    }
    perspectiveWidget->updateGL();
}

void CellMainWindow::setSphereAxisSeg(QString l)
{
    int t = l.toInt();
    if (t>=3) {
        QUndoCommand *sphereInputCommand = new SphereInputCommand(perspectiveWidget, perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getSphereRadius(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getSphereHeightSeg(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getSphereAxisSeg(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getSphereRadius(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getSphereHeightSeg(),
                                                              t);
        undoStack->push(sphereInputCommand);
    }
    perspectiveWidget->updateGL();
}

void CellMainWindow::setCylinderRadius(QString l)
{
    double t = l.toDouble();
    if (t>0.0) {
        QUndoCommand *cylinderInputCommand = new CylinderInputCommand(perspectiveWidget, perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2),
                                                                      (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCylinderRadius(),
                                                                      (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCylinderHeight(),
                                                                      (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCylinderHeightSeg(),
                                                                      (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCylinderAxisSeg(),
                                                                      t,
                                                                      (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCylinderHeight(),
                                                                      (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCylinderHeightSeg(),
                                                                      (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCylinderAxisSeg(),
                                                                      (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getType());
        undoStack->push(cylinderInputCommand);
    }
    perspectiveWidget->updateGL();
}

void CellMainWindow::setCylinderHeight(QString l)
{
    double t = l.toDouble();
    if (t>0.0) {
        QUndoCommand *cylinderInputCommand = new CylinderInputCommand(perspectiveWidget, perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2),
                                                                      (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCylinderRadius(),
                                                                      (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCylinderHeight(),
                                                                      (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCylinderHeightSeg(),
                                                                      (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCylinderAxisSeg(),
                                                                      (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCylinderRadius(),
                                                                      t,
                                                                      (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCylinderHeightSeg(),
                                                                      (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCylinderAxisSeg(),
                                                                      (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getType());
        undoStack->push(cylinderInputCommand);
    }
    perspectiveWidget->updateGL();
}

void CellMainWindow::setCylinderHeightSeg(QString l)
{
    int t = l.toInt();
    if (t>=1) {
        QUndoCommand *cylinderInputCommand = new CylinderInputCommand(perspectiveWidget, perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2),
                                                                      (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCylinderRadius(),
                                                                      (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCylinderHeight(),
                                                                      (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCylinderHeightSeg(),
                                                                      (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCylinderAxisSeg(),
                                                                      (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCylinderRadius(),
                                                                      (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCylinderHeight(),
                                                                      t,
                                                                      (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCylinderAxisSeg(),
                                                                      (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getType());
        undoStack->push(cylinderInputCommand);
    }
    perspectiveWidget->updateGL();
}

void CellMainWindow::setCylinderAxisSeg(QString l)
{
    int t = l.toInt();
    if (t>=3) {
        QUndoCommand *cylinderInputCommand = new CylinderInputCommand(perspectiveWidget, perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2),
                                                                      (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCylinderRadius(),
                                                                      (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCylinderHeight(),
                                                                      (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCylinderHeightSeg(),
                                                                      (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCylinderAxisSeg(),
                                                                      (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCylinderRadius(),
                                                                      (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCylinderHeight(),
                                                                      (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCylinderHeightSeg(),
                                                                      t,
                                                                      (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getType());
        undoStack->push(cylinderInputCommand);
    }
    perspectiveWidget->updateGL();
}

void CellMainWindow::setCubeWidth(QString l)
{
    double t = l.toDouble();
    if (t>0.0) {
        QUndoCommand *cubeInputCommand = new CubeInputCommand(perspectiveWidget, perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeWidth(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeHeight(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeDepth(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeWidthSeg(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeHeightSeg(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeDepthSeg(),
                                                              t,
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeHeight(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeDepth(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeWidthSeg(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeHeightSeg(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeDepthSeg());
        undoStack->push(cubeInputCommand);
    }
    perspectiveWidget->updateGL();
}

void CellMainWindow::setCubeHeight(QString l)
{
    double t = l.toDouble();
    if (t>0.0) {
        QUndoCommand *cubeInputCommand = new CubeInputCommand(perspectiveWidget, perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeWidth(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeHeight(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeDepth(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeWidthSeg(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeHeightSeg(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeDepthSeg(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeWidth(),
                                                              t,
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeDepth(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeWidthSeg(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeHeightSeg(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeDepthSeg());
        undoStack->push(cubeInputCommand);
    }
    perspectiveWidget->updateGL();
}

void CellMainWindow::setCubeDepth(QString l)
{
    double t = l.toDouble();
    if (t>0.0) {
        QUndoCommand *cubeInputCommand = new CubeInputCommand(perspectiveWidget, perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeWidth(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeHeight(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeDepth(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeWidthSeg(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeHeightSeg(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeDepthSeg(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeWidth(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeHeight(),
                                                              t,
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeWidthSeg(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeHeightSeg(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeDepthSeg());
        undoStack->push(cubeInputCommand);
    }
    perspectiveWidget->updateGL();
}

void CellMainWindow::setCubeWidthSeg(QString l)
{
    int t = l.toInt();
    if (t>=1) {
        QUndoCommand *cubeInputCommand = new CubeInputCommand(perspectiveWidget, perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeWidth(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeHeight(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeDepth(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeWidthSeg(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeHeightSeg(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeDepthSeg(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeWidth(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeHeight(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeDepth(),
                                                              t,
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeHeightSeg(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeDepthSeg());
        undoStack->push(cubeInputCommand);
    }
    perspectiveWidget->updateGL();
}

void CellMainWindow::setCubeHeightSeg(QString l)
{
    int t = l.toInt();
    if (t>=1) {
        QUndoCommand *cubeInputCommand = new CubeInputCommand(perspectiveWidget, perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeWidth(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeHeight(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeDepth(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeWidthSeg(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeHeightSeg(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeDepthSeg(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeWidth(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeHeight(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeDepth(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeWidthSeg(),
                                                              t,
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeDepthSeg());
        undoStack->push(cubeInputCommand);
    }
    perspectiveWidget->updateGL();
}

void CellMainWindow::setCubeDepthSeg(QString l)
{
    int t = l.toInt();
    if (t>=1) {
        QUndoCommand *cubeInputCommand = new CubeInputCommand(perspectiveWidget, perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeWidth(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeHeight(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeDepth(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeWidthSeg(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeHeightSeg(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeDepthSeg(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeWidth(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeHeight(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeDepth(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeWidthSeg(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getCubeHeightSeg(),
                                                              t);
        undoStack->push(cubeInputCommand);
    }
    perspectiveWidget->updateGL();
}

void CellMainWindow::setTranslateX(QString l)
{
    double t = l.toDouble();
    if (perspectiveWidget->selectedObject()==0) {
        QUndoCommand *translateCommand = new TranslateCommand(perspectiveWidget,
                                                              perspectiveWidget->getGlandular()->getTranslateX(),
                                                              perspectiveWidget->getGlandular()->getTranslateY(),
                                                              perspectiveWidget->getGlandular()->getTranslateZ(),
                                                              t,
                                                              perspectiveWidget->getGlandular()->getTranslateY(),
                                                              perspectiveWidget->getGlandular()->getTranslateZ(),
                                                              perspectiveWidget->selectedObject());
        undoStack->push(translateCommand);
    } else if (perspectiveWidget->selectedObject()>1) {
        QUndoCommand *translateCommand = new TranslateCommand(perspectiveWidget,
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getTranslateX(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getTranslateY(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getTranslateZ(),
                                                              t,
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getTranslateY(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getTranslateZ(),
                                                              perspectiveWidget->selectedObject());
        undoStack->push(translateCommand);
    }
    perspectiveWidget->updateGL();
}

void CellMainWindow::setTranslateY(QString l)
{
    double t = l.toDouble();
    if (perspectiveWidget->selectedObject()==0) {
        QUndoCommand *translateCommand = new TranslateCommand(perspectiveWidget,
                                                              perspectiveWidget->getGlandular()->getTranslateX(),
                                                              perspectiveWidget->getGlandular()->getTranslateY(),
                                                              perspectiveWidget->getGlandular()->getTranslateZ(),
                                                              perspectiveWidget->getGlandular()->getTranslateX(),
                                                              t,
                                                              perspectiveWidget->getGlandular()->getTranslateZ(),
                                                              perspectiveWidget->selectedObject());
        undoStack->push(translateCommand);
    } else if (perspectiveWidget->selectedObject()>1) {
        QUndoCommand *translateCommand = new TranslateCommand(perspectiveWidget,
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getTranslateX(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getTranslateY(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getTranslateZ(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getTranslateX(),
                                                              t,
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getTranslateZ(),
                                                              perspectiveWidget->selectedObject());
        undoStack->push(translateCommand);
    }
    perspectiveWidget->updateGL();
}

void CellMainWindow::setTranslateZ(QString l)
{
    double t = l.toDouble();
    if (perspectiveWidget->selectedObject()==0) {
        QUndoCommand *translateCommand = new TranslateCommand(perspectiveWidget,
                                                              perspectiveWidget->getGlandular()->getTranslateX(),
                                                              perspectiveWidget->getGlandular()->getTranslateY(),
                                                              perspectiveWidget->getGlandular()->getTranslateZ(),
                                                              perspectiveWidget->getGlandular()->getTranslateX(),
                                                              perspectiveWidget->getGlandular()->getTranslateY(),
                                                              t,
                                                              perspectiveWidget->selectedObject());
        undoStack->push(translateCommand);
    } else if (perspectiveWidget->selectedObject()>1) {
        QUndoCommand *translateCommand = new TranslateCommand(perspectiveWidget,
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getTranslateX(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getTranslateY(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getTranslateZ(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getTranslateX(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getTranslateY(),
                                                              t,
                                                              perspectiveWidget->selectedObject());
        undoStack->push(translateCommand);
    }
    perspectiveWidget->updateGL();
}

void CellMainWindow::setRotateX(QString l)
{
    double t = l.toDouble();
    if (perspectiveWidget->selectedObject()==0) {
        QUndoCommand *rotateCommand = new RotateCommand(perspectiveWidget,
                                                              perspectiveWidget->getGlandular()->getRotateX(),
                                                              perspectiveWidget->getGlandular()->getRotateY(),
                                                              perspectiveWidget->getGlandular()->getRotateZ(),
                                                              t,
                                                              perspectiveWidget->getGlandular()->getRotateY(),
                                                              perspectiveWidget->getGlandular()->getRotateZ(),
                                                              perspectiveWidget->selectedObject());
        undoStack->push(rotateCommand);
    } else if (perspectiveWidget->selectedObject()>1) {
        QUndoCommand *rotateCommand = new RotateCommand(perspectiveWidget,
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getRotateX(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getRotateY(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getRotateZ(),
                                                              t,
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getRotateY(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getRotateZ(),
                                                              perspectiveWidget->selectedObject());
        undoStack->push(rotateCommand);
    }
    perspectiveWidget->updateGL();
}

void CellMainWindow::setRotateY(QString l)
{
    double t = l.toDouble();
    if (perspectiveWidget->selectedObject()==0) {
        QUndoCommand *rotateCommand = new RotateCommand(perspectiveWidget,
                                                              perspectiveWidget->getGlandular()->getRotateX(),
                                                              perspectiveWidget->getGlandular()->getRotateY(),
                                                              perspectiveWidget->getGlandular()->getRotateZ(),
                                                              perspectiveWidget->getGlandular()->getRotateX(),
                                                              t,
                                                              perspectiveWidget->getGlandular()->getRotateZ(),
                                                              perspectiveWidget->selectedObject());
        undoStack->push(rotateCommand);
    } else if (perspectiveWidget->selectedObject()>1) {
        QUndoCommand *rotateCommand = new RotateCommand(perspectiveWidget,
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getRotateX(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getRotateY(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getRotateZ(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getRotateX(),
                                                              t,
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getRotateZ(),
                                                              perspectiveWidget->selectedObject());
        undoStack->push(rotateCommand);
    }
    perspectiveWidget->updateGL();
}

void CellMainWindow::setRotateZ(QString l)
{
    double t = l.toDouble();
    if (perspectiveWidget->selectedObject()==0) {
        QUndoCommand *rotateCommand = new RotateCommand(perspectiveWidget,
                                                              perspectiveWidget->getGlandular()->getRotateX(),
                                                              perspectiveWidget->getGlandular()->getRotateY(),
                                                              perspectiveWidget->getGlandular()->getRotateZ(),
                                                              perspectiveWidget->getGlandular()->getRotateX(),
                                                              perspectiveWidget->getGlandular()->getRotateY(),
                                                              t,
                                                              perspectiveWidget->selectedObject());
        undoStack->push(rotateCommand);
    } else if (perspectiveWidget->selectedObject()>1) {
        QUndoCommand *rotateCommand = new RotateCommand(perspectiveWidget,
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getRotateX(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getRotateY(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getRotateZ(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getRotateX(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getRotateY(),
                                                              t,
                                                              perspectiveWidget->selectedObject());
        undoStack->push(rotateCommand);
    }
    perspectiveWidget->updateGL();
}

void CellMainWindow::setScaleX(QString l)
{
    double t = l.toDouble();
    if (perspectiveWidget->selectedObject()==0) {
        QUndoCommand *scaleCommand = new ScaleCommand(perspectiveWidget,
                                                              perspectiveWidget->getGlandular()->getScaleX(),
                                                              perspectiveWidget->getGlandular()->getScaleY(),
                                                              perspectiveWidget->getGlandular()->getScaleZ(),
                                                              t,
                                                              perspectiveWidget->getGlandular()->getScaleY(),
                                                              perspectiveWidget->getGlandular()->getScaleZ(),
                                                              perspectiveWidget->selectedObject());
        undoStack->push(scaleCommand);
    } else if (perspectiveWidget->selectedObject()>1) {
        QUndoCommand *scaleCommand = new ScaleCommand(perspectiveWidget,
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getScaleX(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getScaleY(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getScaleZ(),
                                                              t,
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getScaleY(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getScaleZ(),
                                                              perspectiveWidget->selectedObject());
        undoStack->push(scaleCommand);
    }
    perspectiveWidget->updateGL();
}

void CellMainWindow::setScaleY(QString l)
{
    double t = l.toDouble();
    if (perspectiveWidget->selectedObject()==0) {
        QUndoCommand *scaleCommand = new ScaleCommand(perspectiveWidget,
                                                              perspectiveWidget->getGlandular()->getScaleX(),
                                                              perspectiveWidget->getGlandular()->getScaleY(),
                                                              perspectiveWidget->getGlandular()->getScaleZ(),
                                                              perspectiveWidget->getGlandular()->getScaleX(),
                                                              t,
                                                              perspectiveWidget->getGlandular()->getScaleZ(),
                                                              perspectiveWidget->selectedObject());
        undoStack->push(scaleCommand);
    } else if (perspectiveWidget->selectedObject()>1) {
        QUndoCommand *scaleCommand = new ScaleCommand(perspectiveWidget,
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getScaleX(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getScaleY(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getScaleZ(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getScaleX(),
                                                              t,
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getScaleZ(),
                                                              perspectiveWidget->selectedObject());
        undoStack->push(scaleCommand);
    }
    perspectiveWidget->updateGL();
}

void CellMainWindow::setScaleZ(QString l)
{
    double t = l.toDouble();
    if (perspectiveWidget->selectedObject()==0) {
        QUndoCommand *scaleCommand = new ScaleCommand(perspectiveWidget,
                                                              perspectiveWidget->getGlandular()->getScaleX(),
                                                              perspectiveWidget->getGlandular()->getScaleY(),
                                                              perspectiveWidget->getGlandular()->getScaleZ(),
                                                              perspectiveWidget->getGlandular()->getScaleX(),
                                                              perspectiveWidget->getGlandular()->getScaleY(),
                                                              t,
                                                              perspectiveWidget->selectedObject());
        undoStack->push(scaleCommand);
    } else if (perspectiveWidget->selectedObject()>1) {
        QUndoCommand *scaleCommand = new ScaleCommand(perspectiveWidget,
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getScaleX(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getScaleY(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getScaleZ(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getScaleX(),
                                                              (perspectiveWidget->getObjects().at(perspectiveWidget->selectedObject()-2))->getScaleY(),
                                                              t,
                                                              perspectiveWidget->selectedObject());
        undoStack->push(scaleCommand);
    }
    perspectiveWidget->updateGL();
}

void CellMainWindow::unionSlot()
{
    //if an object is selected && a second object is selected && the 1st object != 2nd object
    if (perspectiveWidget->selectedObject()>=2 && perspectiveWidget->secondSelectedObject()>=2 &&
            perspectiveWidget->selectedObject()!=perspectiveWidget->secondSelectedObject())
    {
        QUndoCommand *unionCommand = new UnionCommand(perspectiveWidget,
                                                      perspectiveWidget->selectedObject(),
                                                      perspectiveWidget->secondSelectedObject());
        undoStack->push(unionCommand);
    }
    perspectiveWidget->updateGL();
}

void CellMainWindow::subtractSlot()
{
    if (perspectiveWidget->selectedObject()>=2&&perspectiveWidget->secondSelectedObject()>=2&&
            perspectiveWidget->selectedObject()!=perspectiveWidget->secondSelectedObject()) {
        QUndoCommand *subtractCommand = new SubtractCommand(perspectiveWidget,
                                                            perspectiveWidget->selectedObject(),
                                                            perspectiveWidget->secondSelectedObject());
        undoStack->push(subtractCommand);
    }
    perspectiveWidget->updateGL();
}

void CellMainWindow::intersectSlot()
{
    if (perspectiveWidget->selectedObject()>=2&&perspectiveWidget->secondSelectedObject()>=2&&
            perspectiveWidget->selectedObject()!=perspectiveWidget->secondSelectedObject()) {
        QUndoCommand *intersectCommand = new IntersectCommand(perspectiveWidget,
                                                              perspectiveWidget->selectedObject(),
                                                              perspectiveWidget->secondSelectedObject());
        undoStack->push(intersectCommand);
    }
    perspectiveWidget->updateGL();
}
